package cn.supermaster.management.web.service.monitor.impl;

import cn.supermaster.management.common.page.TableDataInfo;
import cn.supermaster.management.common.response.WebResponse;
import cn.supermaster.management.common.utils.WebHelper;
import cn.supermaster.management.common.utils.poi.ExcelUtil;
import cn.supermaster.management.system.domain.SystemOperateLog;
import cn.supermaster.management.system.service.ISystemOperateLogService;
import cn.supermaster.management.web.service.monitor.IMonitorOperateLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.ModelMap;

import java.util.List;

/**
 * All rights Reserved, Designed By www.super-bytecode.com
 *
 * @ProjectName: supermaster-management
 * @Package: cn.supermaster.management.web.service.monitor.impl
 * @ClassName: MonitorOperateLogServiceImpl
 * @Description: [操作日志记录]
 * <p> </p>
 * @Author: [Lance Ting]
 * @Date: 2021/1/10 16:54
 * @Version: V1.0
 * @Copyright: 2021 www.super-bytecode.comn Inc. All rights reserved.
 * TODO: 注意,本文件Lance Ting所作,如果转载或使用请标明具体出处!
 **/
@Service
public class MonitorOperateLogServiceImpl implements IMonitorOperateLogService {

    private String prefix = "monitor/operlog";

    @Autowired
    private ISystemOperateLogService operateLogService;

    /*
     * ================================================
     *  页面跳转功能实现
     * ================================================
     */

    /**
     * @Description: [跳转操作日志界面]
     * <p></P>
     * @Title: skipOperateLogHtml
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param:
     * @Return: java.lang.String
     * @Throws:
     */
    @Override
    public String skipOperateLogHtml() {
        return prefix + "/operlog";
    }

    /**
     * @Description: [跳转到操作日志详情界面]
     * <p></P>
     * @Title: skipOperateLogDetailHtml
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: modelMap
     * @Param: operateLogId
     * @Return: java.lang.String
     */
    @Override
    public String skipOperateLogDetailHtml(ModelMap modelMap, Long operateLogId) {
        SystemOperateLog operateLog = operateLogService.selectOperLogById(operateLogId);
        modelMap.put("operLog", operateLog);
        return prefix + "/detail";
    }

    /*
     * ================================================
     *  Rest功能实现
     * ================================================
     */

    /**
     * @Description: [获取操作日志列表]
     * <p></P>
     * @Title: queryOperateLogList
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: operateLog
     * @Return: cn.supermaster.management.common.page.TableDataInfo
     */
    @Override
    public TableDataInfo queryOperateLogList(SystemOperateLog operateLog) {
        WebHelper.startPage();
        List<SystemOperateLog> list = operateLogService.selectOperLogList(operateLog);
        TableDataInfo result = WebHelper.getDataTable(list);
        //
        return result;
    }

    /**
     * @Description: [导出操作日志记录]
     * <p></P>
     * @Title: doExportOperateLog
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: operateLog
     * @Return: cn.supermaster.management.common.response.WebResult
     */
    @Override
    public WebResponse doExportOperateLog(SystemOperateLog operateLog) {
        List<SystemOperateLog> list = operateLogService.selectOperLogList(operateLog);
        ExcelUtil<SystemOperateLog> util = new ExcelUtil<SystemOperateLog>(SystemOperateLog.class);
        WebResponse result = util.exportExcel(list, "操作日志");
        //
        return result;
    }

    /**
     * @Description: [删除操作日志记录]
     * <p></P>
     * @Title: doRemoveOperateLog
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Param: ids
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse doRemoveOperateLog(String ids) {
        int rows = operateLogService.deleteOperLogByIds(ids);
        WebResponse result = WebHelper.webResult(rows);
        //
        return result;
    }

    /**
     * @Description: [清空操作日志记录]
     * <p></P>
     * @Title: doCleanOperateLog
     * @Author: Lance Ting
     * @Date: 2021-01-10
     * @Return: cn.supermaster.management.common.response.WebResult
     * @Throws:
     */
    @Override
    public WebResponse doCleanOperateLog() {
        operateLogService.cleanOperLog();
        WebResponse result = WebHelper.success();
        //
        return result;
    }
}